package com.example.kotlindemo.pages
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.example.kotlindemo.R
import com.google.android.material.bottomnavigation.BottomNavigationView

class TabLayoutActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // enableEdgeToEdge()
        setContentView(R.layout.activity_tab_layout)
        val navView: BottomNavigationView = findViewById(R.id.nav_view)

        try {
            val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_activity_main) as? NavHostFragment ?: throw IllegalStateException("NavHostFragment not found. Check your layout file.") // 使用安全转换 as?
            val navController: NavController = navHostFragment.navController
            navView.setupWithNavController(navController)
        }catch (e:Exception){
            Log.e("TabLayout" , "tabLayout failed：$e")
        }

    }
}